﻿<?php 
	include_once '../action/checkLogin.php';
	include_once '../../public/inc/DB.php';
	$db = new DB('jusmor_news');
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>文章列表</title>
    <link type="text/css" rel="stylesheet" href="/public/css/bootstrap.min.css" />

    <script type="text/javascript" src="/public/js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="/public/js/bootstrap.min.js"></script>

    <script type="text/javascript" src="/public/js/tools.js"></script>
</head>
<body>
    <div class="container col-lg-12 ">
        <h3 style="border-bottom: 3px solid #336699; padding-bottom: 2px;"><strong>文章列表</strong></h3>
        <div class="table-responsive">
            <table class="table table-bordered table-hover">
                <thead style="background:#EEEEEE;">
                    <th>ID</th>
                    <th>文章标题</th>
                    <th>文章分类</th>
                    <th>操作</th>
                </thead>
                <tbody>
				<?php 
					$condition = array('status'=>1);
					$fields = 'news_id, news_title, news_content, news_cate_id';
					$news_list = $db->fetchAll($condition, $fields);
					if(! empty($news_list)) {
						foreach ($news_list as $key=>$val) {
							//获取分类名称
							$condition = array('status'=>1, 'news_cate_id'=>$val['news_cate_id']);
							$fields = 'news_cate_name';
							$news_cate_id_res = $db->fetch($condition, $fields, 'jusmor_news_cate');
				?>
                    	<tr>
	                       	<td><?php echo $val['news_id'];?></td>
	                       	<td><?php echo $val['news_title'];?></td>
	                       	<td><?php echo $news_cate_id_res['news_cate_name'];?></td>
	                       	<td>
	                       		<a class="btn btn-primary btn-xs" role="button" href="news_edit.php?news_id=<?php echo $val['news_id'] ?>">编辑</a>
	                       		<a type="button" class="btn btn-danger btn-xs del_news" data-id="<?php echo $val['news_id'] ?>">删除  </a>
	                       	</td>
                    	</tr>
                <?php 
                		}
					} else {
				?>
                		<tr><td class="text-center" colspan="4">没有发布文章！</td></tr>
                <?php
					}
				?>
                </tbody>
            </table>
        </div>
    </div>
    <script type="text/javascript">
    	$(function(){
			$(".del_news").click(function(){
				var _this = $(this);
				var _tr = _this.closest("tr");
				var news_id = _this.attr("data-id");
				if(news_id != "") {
					if(confirm("确认删除？")) {
						var _url = "../ajaxAPI/newsAPI.php"	;
						var _param = {"news_id":news_id, "action":"del_news"};
						$.post(_url, _param, function(data){
							if(data.code == 1) {
								 _tr.hide("500", function () {
                                    _tr.remove();
									alert("删除成功！");
                                });
							} else {
								alert(data.msg);	
							}
						}, "json");
					}
				}
			});	
		})
    </script>
</body>
</html>
